import { PURCHASEWAY_OPTIONS } from '@/constant/purchase'
import { phoneVerify } from '@/utils/validator'
import { Empty } from 'antd'
export const useFormEdit = ({
  orgOptions,
  handleSearchOrg,
  qsfOrgId,
  reset,
}: {
  orgOptions: IOptionItem[]
  handleSearchOrg: (newValue?: string) => void
  qsfOrgId: number
  reset: () => void
}): IItemArray[] => {
  return [
    {
      name: 'org',
      label: '组织名称',
      type: 'Select',
      placeholder: '请选择组织名称',
      option: orgOptions,
      config: {
        suffixIcon: null,
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        labelInValue: true,
        onSearch: handleSearchOrg,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
        onClear: () => {
          handleSearchOrg()
        },
      },
      rules: [
        {
          required: true,
          message: '请选择组织名称',
        },
      ],
    },
    {
      name: 'name',
      label: '用户姓名',
      type: 'Input',
      placeholder: '请输入用户姓名',
      rules: [
        {
          required: true,
          message: '请输入用户姓名',
        },
      ],
      config: {
        showCount: true,
        maxLength: 10,
      },
    },
    {
      name: 'workId',
      label: '用户工号',
      type: 'Input',
      placeholder: '请输入用户工号',
      rules: [
        {
          required: true,
          message: '请输入用户工号',
        },
      ],
      config: {
        showCount: true,
        maxLength: 10,
      },
      hidden: qsfOrgId != 1,
    },
    {
      name: 'phone',
      label: '用户手机号',
      type: 'Input',
      placeholder: '请输入用户手机号',
      rules: [
        {
          required: true,
          message: '请输入用户手机号',
        },
        { validator: phoneVerify },
      ],
    },
  ]
}

export const useFormSupplier = ({
  supplierOption,
  isSupplierEdit,
  isShowSelect,
  setisShowSelect,
  isRoot,
  isShowBigClass,
  setisShowBigClass,
  classIdOptions,
}: {
  supplierOption: IOptionItem[]
  classIdOptions: IOptionItem[]
  isSupplierEdit: boolean
  isShowSelect: boolean
  setisShowSelect: React.Dispatch<React.SetStateAction<boolean>>
  isShowBigClass: boolean
  setisShowBigClass: React.Dispatch<React.SetStateAction<boolean>>
  isRoot: boolean
}): IItemArray[] => {
  return [
    {
      name: 'allSupplier',
      label: '全部供应商权限',
      type: 'Radio',
      option: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      hidden: !isRoot,
      config: {
        onChange: (event: any) => {
          if (event?.target.value == 0) {
            setisShowSelect(true)
          } else {
            setisShowSelect(false)
          }
        },
      },
    },
    {
      name: 'supplier',
      label: '供应商权限',
      type: 'Select',
      option: supplierOption,
      hidden: !isShowSelect,
      placeholder: '请选择供应商',
      config: {
        mode: 'multiple',
        optionFilterProp: 'label',
        disabled: !isSupplierEdit,
      },
    },
    {
      name: 'allClassAuthority',
      label: '全部大类权限',
      type: 'Radio',
      option: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      hidden: !isRoot,
      config: {
        onChange: (event: any) => {
          if (event?.target.value == 0) {
            setisShowBigClass(true)
          } else {
            setisShowBigClass(false)
          }
        },
      },
    },
    {
      name: 'classAuthority',
      label: '大类权限',
      type: 'Select',
      option: classIdOptions,
      hidden: !isShowBigClass,
      placeholder: '请选择大类',
      config: {
        mode: 'multiple',
        optionFilterProp: 'label',
        disabled: !isSupplierEdit,
      },
    },
    {
      name: 'purchaseTypePermission',
      label: '采购方式权限',
      type: 'Select',
      option: PURCHASEWAY_OPTIONS,
      placeholder: '请选择采购方式权限',
      hidden: !isRoot,
      config: {
        mode: 'multiple',
        optionFilterProp: 'label',
      },
    },
  ]
}
